from flask import Blueprint
from flask import redirect
from flask import request
from flask import session

admin_blue = Blueprint("login",__name__,url_prefix="/admin")

from . import views


#设置请求钩子拦截普通用户
@admin_blue.before_request
def visit_admin():
    # 拦截非管理员用户登陆管理员非登陆页面
    #管理员不需要拦截
    # if request.url.endswith("/admin/login"):
    #     pass
    # else:
    #     # 判断是否时管理员
    #     if session.get("is_admin"):
    #         pass
    #     else:
    #         return redirect("/")

    # 优化
    if not request.url.endswith("/admin/login"):
        if not session.get("is_admin"):
            return redirect("/")